const app = getApp();
const regeneratorRuntime = getApp().globalData.regeneratorRuntime;
const ajaxHelp = getApp().globalData.ajaxHelp;
const serviceUrl = getApp().globalData.serviceUrl;
const util = require('../../utils/util.js');

module.exports = Behavior({
	behaviors: [],
	properties: {},
	data: {},
	methods: {
		//同步模式窗口
		showModalSync: function(title, content) {
			return new Promise((resolve, reject) => {
				wx.showModal({
					title: title,
					content: content,
					showCancel: false,
					success: function(sm) {
						resolve(sm);
					},
					fail: function(err) {
						reject(err);
					}
				})
			});
		},

		async setUserStorage(token) {
			var result = await ajaxHelp.asyncOAuthGet(serviceUrl + '/api/User', token, {});
			console.log(result.data, result.data.mobilerole_systemuser);
			
			//debugger;
      app.globalData.userInfo = result.data;
			wx.setStorageSync('useridentity', result.data);
			wx.setStorageSync('token', token);
		},

		async LoginPwd() {
			try {
				if (this.data.isRememberPwd) {
					wx.setStorageSync('userpwd', {
						user: this.data.no,
						pwd: this.data.pwd
					});
				}


				var result = await ajaxHelp.asyncPost(serviceUrl + '/token', {
					grant_type: "password",
					UserName: this.data.no,
					Password: this.data.pwd
				});

				return result;
			} catch (e) {
				//TODO handle the exception			
				console.log(e);
			}
		},
	}

})
